﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using game.display.object2d;

namespace game.display.hud
{

    public class HUD
    {

        protected const string _HealthBackground = "Graphics/HUD/HealthBackground";
        protected const string _HealthBar = "Graphics/HUD/HealthBar";
        protected const string _HealthCover = "Graphics/HUD/HealthCover";
        public Microsoft.Xna.Framework.Vector2 _HealthPostion = new Microsoft.Xna.Framework.Vector2(32, 32);

        protected const string _TimerFont = "Graphics/HUD/Arial";
        protected const float _TimerMilliseconds = 600000.0f;
        public Microsoft.Xna.Framework.Vector2 _TimerPosition = new Microsoft.Xna.Framework.Vector2(Global.DefaultScreenSize.X - 196, 64);

        protected const string _Life = "Graphics/HUD/Life";
        public Microsoft.Xna.Framework.Vector2 _LifePosition = new Microsoft.Xna.Framework.Vector2(32, Global.DefaultScreenSize.Y - 64);

        protected const string _RouteBackground = "Graphics/HUD/RouteBackground";
        protected const string _RouteBar = "Graphics/HUD/RouteBar";
        protected const string _RouteCover = "Graphics/HUD/RouteCover";
        public Microsoft.Xna.Framework.Vector2 _RoutePosition = Global.DefaultScreenSize - new Microsoft.Xna.Framework.Vector2(160, 32);

        public readonly SpriteBar Health;
        public readonly HUDTimer Timer;
        public readonly HUDLives Lives;
        public readonly SpriteBar Route;

        public HUD(lumo.LumoComponent component)
        {

            #region Health

            Microsoft.Xna.Framework.Graphics.Texture2D background =
                component.Content.Load<Microsoft.Xna.Framework.Graphics.Texture2D>(_HealthBackground);
            Microsoft.Xna.Framework.Graphics.Texture2D bar =
                component.Content.Load<Microsoft.Xna.Framework.Graphics.Texture2D>(_HealthBar);
            Microsoft.Xna.Framework.Graphics.Texture2D cover =
                component.Content.Load<Microsoft.Xna.Framework.Graphics.Texture2D>(_HealthCover);

            Health = new SpriteBar(background, bar, cover);
            for (int i = 0; i < Health.Sprites.Length; i++)
                Health.Sprites[i].Position = _HealthPostion;

            #endregion

            #region Timer

            Microsoft.Xna.Framework.Graphics.SpriteFont spriteFont =
                component.Content.Load<Microsoft.Xna.Framework.Graphics.SpriteFont>(_TimerFont);
            Timer = new HUDTimer(spriteFont, _TimerMilliseconds);

            Timer.Position = _TimerPosition;

            #endregion

            #region Lives

            background = component.Content.Load<Microsoft.Xna.Framework.Graphics.Texture2D>(_Life);
            Lives = new HUDLives(background);

            Lives.Position = _LifePosition;

            #endregion

            #region Route

            background = component.Content.Load<Microsoft.Xna.Framework.Graphics.Texture2D>(_RouteBackground);
            bar = component.Content.Load<Microsoft.Xna.Framework.Graphics.Texture2D>(_RouteBar);
            cover = component.Content.Load<Microsoft.Xna.Framework.Graphics.Texture2D>(_RouteCover);

            Route = new SpriteBar(background, bar, cover);
            for (int i = 0; i < Route.Sprites.Length; i++)
                Route.Sprites[i].Position = _RoutePosition;

            #endregion

        }

        public void Update(lumo.LumoComponent component)
        {
            Health.Update(component);
            Timer.Update(component);
            Route.Update(component);
        }

        public void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            Health.Draw(spriteBatch);
            Timer.Draw(spriteBatch);
            Lives.Draw(spriteBatch);
            Route.Draw(spriteBatch);
        }

    }

}